﻿using System.Windows;
using System.Windows.Controls.Primitives;
using Microsoft.Practices.Prism.Commands;
using System.Windows.Controls;
using System.Windows.Navigation;

namespace Ausy.Silverlight.Survey.Common.Extensions.Commands
{
    /// <summary>
    /// Cette classe représente la commande permettant de gérer la gestion de la navigation en cours
    /// </summary>
    public class NavigatingCommand : CommandBehaviorBase<Frame>
    {
        #region Constructor

        /// <summary>
        /// Constructeur par défaut
        /// </summary>
        /// <param name="element">Frame de navigation</param>
        public NavigatingCommand(Frame element)
            : base(element)
        {
            element.Navigating += this.OnNavigating;
        } 

        #endregion

        #region OnNavigating Method

        /// <summary>
        /// Cette méthode permet de gérer la navigation dur la Frame
        /// </summary>
        /// <param name="sender">Frame associé</param>
        /// <param name="e">Argument de navigation</param>
        private void OnNavigating(object sender, NavigatingCancelEventArgs e)
        {
            var frame = sender as Frame;
            base.CommandParameter = e.Uri;
            base.ExecuteCommand();
        } 

        #endregion
    }
}
